Coordinate Systems


Mapping Mode

A mapping mode allows moving the origin of the coordinate system from the top left corner to a new position. A mapping mode allows scaling the axis. It is said that a mapping mode defines a mapping from the window (logic coordinates) to a viewport (device coordinates). The API TextOut, as almost all GDI functions, uses a coordinate values in logic units. Microsoft Windows must convert these logic units to device units (pixels) before performing any drawing.
Un modo de mapeo permite mover el origen del sistema de coordenadas de la esquina superior izquierda a una nueva posición. El modo de mapeo también permite escalar los tamaños de los ejes. Se dice que un modo de mapeo define un mapeo desde la ventana (coordenadas lógicas) a un puerto de visión (viewport con coordernadas de dispositivo.) La API TextOut, como casi todas las funciones de la GDI, utilizan valores de coordenadas que son unidades lógicas. Microsoft Windows debe convertir estas unidades lógicas en una unidad de dispositivo (pixeles) antes de hacer cualquier operación de dibujado.

Tip
In the code below, the mapping mode is used to transform the coordinate system to the system used in mathematics where the origin is in the center, and the Y-axis goes to the top. In this case, the cross always has the same proportion and position when the window resizes. The width of the window is 2000 logic unit no matter the size of the window in pixels.
En el código de abajo, el modo de mapeo es usado para transformar el sistema de coordenadas al sistema usado en matemáticas donde el origen está al centro, y el eje Y va hacia arriba. En este caso, la cruz siempre tiene la misma proporción y posición cuando la ventana cambia de tamaño. El ancho de la ventana es de 2000 unidades lógicas sin importar el tamaño de la ventana en pixeles.

Program.cpp
void Program::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);

     gdi.SetMapMode(MM_ISOTROPIC);

     //__________________________ 1000 map to width/2, 1000 map to -height/2
     //__________________________ From: logic units to pixels
     gdi.SetWindowExtEx(1000, 1000, NULL);
     gdi.SetViewportExtEx(width/2, -height/2, NULL);
     //
     gdi.SetWindowOrgEx(0, 0, NULL);
     gdi.SetViewportOrgEx(width/2, height/2, NULL); // Moves the origin to center (in pixels)
     //
     gdi.Line(-500, 0, 500, 0);
     gdi.Line(0, 500, 0, -500);
}

Cross1

Cross2

Problem 1
Create a program called SenoMap to draw a sine wave a shown using the mapping modes. You may map the X axis from 0 to 1256, and the Y axis from -1000 to 1000.
Cree un programa llamado SenoMap para dibujar una onda senoidal como se muestra usando los modos de mapeo. Usted puede mapear el eje X desde 0 a 1256 y el eje Y desde -1000 a 1000.

SenoMap.h
#pragma once //______________________________________ SenoMap.h
#include "resource.h"
#define POINT_COUNT 1024
class SenoMap: public Win::Window
{
public:
     SenoMap()
     {
     }
     ~SenoMap()
     {
     }
     POINT point[POINT_COUNT];
     ...
};


SenoMap.cpp
...

#include "stdafx.h" //________________________________________ SenoMap.cpp
#include "SenoMap.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR cmdLine, int cmdShow){
     SenoMap app;
     CG::Brush brush(RGB(0, 0, 0));
     app.CreateMainWindow(L"SenoMap", cmdShow, IDI_SENOMAP, NULL, brush, hInstance);
     return app.MessageLoop(IDC_SENOMAP);
}

void SenoMap::Window_Open(Win::Event& e)
{
     const double delta= (2.0*M_PI)/(POINT_COUNT-1);
     double x, y;
     for(int i = 0; i < POINT_COUNT; i++)
     {
          x = i*delta;
          y = sin(x);
          //
          point[i].x = i;
          point[i].y = (int)(1000*y+0.5);
     }
}

void SenoMap::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     CG::Pen pen;
     pen.Create(PS_SOLID, 3, RGB(0, 255, 0));
     gdi.Select(pen);
     gdi.SetMapMode(MM_ANISOTROPIC);
     //__________________________ POINT_COUNT maps to width, 1000 maps to -height/2
     gdi.SetWindowExtEx(POINT_COUNT, 1000, NULL);
     gdi.SetViewportExtEx(width, -height/2, NULL);
     //
     gdi.SetWindowOrgEx(0, 0, NULL);
     gdi.SetViewportOrgEx(0, height/2, NULL); // Moves the origin to the left center (in pixels)
     gdi.Polyline(point, POINT_COUNT);
}


SenoMap1

SenoMap2

Problem 2
Create a Window Application called RotaBox to test rotation and translation using an affine transformation.
Cree una Aplicación de Ventana llamada RotaBox para probar la rotación y la translación usando una tranformación affine.

RotaBox.cpp
...
void RotaBox::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     RECT rect = {-100, -100, 100, 200};
     //____________________________________ 1. Before
     gdi.Rectangle(rect);
     //____________________________________ 2. After
     gdi.SetAdvancedMode(true);
     gdi.SetWorldTransformation(20.0, width/2, height/2);
     gdi.Rectangle(rect);
     gdi.SetAdvancedMode(false);
}


RotaBoxRun

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home